<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="com.dsrk.sysusage.*"%>
<%@ page import="java.sql.ResultSet"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>right</title>
</head>
<body>
<%
	String TYPE = request.getParameter("TYPE");
	String groupname = request.getParameter("groupname");
	String property = request.getParameter("property");
%>
<%=TYPE%>
,
<%=groupname%>
,
<%=property%>
<br>
<%
	Display display = new Display();

	if (TYPE != null) {
		if (TYPE.equals("tr_hourly")) {
			String query = "SELECT TIMESTAMP, SUM(CNT) AS CNT"
			+ " FROM ("
			+ " SELECT CHAR(DATE(timestamp))||' 0'||RTRIM(CHAR(HOUR(timestamp)))||':00',VALUE"
			+ " FROM sysusage_rawdata"
			+ " WHERE HOUR(timestamp)<10 AND property LIKE  '%"
			+ property
			+ "%' "
			+ " UNION"
			+ " SELECT CHAR(DATE(timestamp))||' '||RTRIM(CHAR(HOUR(timestamp)))||':00',VALUE"
			+ " FROM sysusage_rawdata"
			+ " WHERE HOUR(timestamp)>=10 AND property LIKE  '%"
			+ property + "%' " + " ) V1(timestamp, cnt)"
			+ " GROUP BY timestamp ORDER BY timestamp";

			out.println(display.dumpData(display.Query(query)));
		} else if (TYPE.equals("tr_daily")) {
			String query = "SELECT TIMESTAMP, SUM(CNT)AS CNT"
			+ " FROM (" + " SELECT CHAR(DATE(timestamp)),VALUE"
			+ " FROM sysusage_rawdata"
			+ " WHERE property LIKE  '%" + property
			+ "%' ) V1(timestamp, cnt)"
			+ " GROUP BY timestamp ORDER BY timestamp";

			out.println(display.dumpData(display.Query(query)));
		} else if (TYPE.equals("cpu")) {
			out.println(display.DisplayCpuByGroup(groupname));
		} else if (TYPE.equals("mem")) {
			if (groupname.equals("") || groupname == null) {
		ResultSet rs = display
				.Query("SELECT DISTINCT groupname, level FROM sysusage_group");
		while (rs.next()) {
			groupname = rs.getString(1);
			String level = rs.getString(2);
			out.println("<b>" + groupname + " , " + level
			+ "</b>");
			out.println(new Display()
			.DisplayMemByGroup(groupname));
			out.println("<br>");
		}
			} else {
		out.println(display.DisplayMemByGroup(groupname));
			}
		} else if (TYPE.equals("disk")) {
			if (property.equals("") || property == null) {
		ResultSet rs = display
				.Query("SELECT DISTINCT property FROM sysusage_rawdata WHERE property like 'disk%' AND property NOT LIKE '%tot'");
		while (rs.next()) {
			property = rs.getString(1);
			out.println("<b>" + property + "</b>");
			out.println(new Display()
			.DisplayDiskByProperty(property));
			out.println("<br>");
		}
			} else {
		out.println(display.DisplayDiskByProperty(property));
			}
		} else if (TYPE.equals("nic")) {
			if (groupname.equals("") || groupname == null) {
		ResultSet rs = display
				.Query("SELECT DISTINCT groupname, level FROM sysusage_group");
		while (rs.next()) {
			groupname = rs.getString(1);
			out.println("<b>" + groupname + "</b>");
			out.println(new Display()
			.DisplayNicByGroup(groupname));
			out.println("<br>");
		}
			} else {
		out.println(display.DisplayNicByGroup(groupname));
			}
		}
	}
%>
</body>
</html>
